<template>
	<view class="log_off column">
		<view class="flex-1 hb column scrolly">
			<u-parse :content="log_off_content" />
		</view>
		<view class="mtb20">
			<up-checkbox label="同意注销协议相关内容" name="agree" usedAlone v-model:checked="aloneChecked" shape="circle" />
		</view>
		<view class="align-center mb50">
			<u-button text="确认注销" type="primary" :customStyle="{height:'90rpx'}" shape="circle" @click="onConfirmOff" />
		</view>
	</view>
</template>

<script setup>
	import {
		onLoad
	} from "@dcloudio/uni-app";
	import {
		ref
	} from "vue";
	import {
		getArticle
	} from "@/api/article.js";
	import {
		logoff
	} from "@/api/user/index.js";
	import {
		formatRich,
		navTo,
		showModel,
		showSuccess,
		showToast
	} from "@/core/app";
	import {
		useStore
	} from "vuex";
	onLoad(() => {
		getLogOff()
	})
	const aloneChecked = ref(false)
	const log_off_content = ref('')
	const getLogOff = async () => {
		let res = await getArticle({
			code: 'log_off'
		})
		if (res) {
			log_off_content.value = formatRich(res.data.content)
		}
	}
	const store = useStore()
	const onConfirmOff = () => {
		if (!aloneChecked.value) return showToast('请仔细阅读并勾选注销协议')
		showModel({
			content: '确认要注销账号吗?',
			confirm: async () => {
				let res = await logoff()
				if (res) {
					showSuccess('账号注销成功')
					store.dispatch('Logout')
					setTimeout(() => {
						navTo('pages/home/index', {}, 'redirectTo')
					}, 1000)
				}
			}
		})

	}
</script>

<style lang="scss" scoped>
	.log_off {
		padding: 30rpx;
		height: calc(100% - 60rpx);
	}
</style>